﻿using BaseDao;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AMInstantMessagingServerDao
{
    public class FriendProvider : MemoryBaseProvider<FriendModel>
    {
        /// <summary>
        /// 根据UserId获取全部的朋友信息
        /// </summary>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public IEnumerable<FriendModel> GetAllFriendByUserId(long user_id)
        {
            return GetItemListCacheModel(GetItemListCacheKey(string.Format("AllFriendOfUser:{0}", user_id)));
        }

        /// <summary>
        /// 添加一个好友关系
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public override bool Add(FriendModel model)
        {
            string cache_key = GetItemListCacheKey(string.Format("AllFriendOfUser:{0}", model.UserId));
            Databse.SetAdd(cache_key, model.Id);
            return base.Add(model);
        }
    }
}
